/**
 * Created by tanjian on 2017/4/14.
 */
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin"); //额外安装的wepback关于css分离打包的插件。
//postcss插件配置项
const autoprefixer = require('autoprefixer');
const postcssOpts = {
  ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
  plugins: () => [
    autoprefixer({
      browsers: ['last 2 versions', 'Firefox ESR', '> 1%', "ie >= 9", "Firefox >= 20", "Chrome >= 48", "Safari >= 8"],
    }),
    // pxtorem({ rootValue: 100, propWhiteList: [] })
  ],
};
module.exports = {
  entry: {
    index: path.resolve(__dirname, './src/component/indexRoute.js'),
    login: path.resolve(__dirname, './src/component/loginRoute.js'),
    expressBill: path.resolve(__dirname, './src/component/expressBillRoute.js'),
    shared: ['react', 'react-dom', 'react-router', 'jquery', 'moment'],
  },
  output: {
    path: path.resolve(__dirname, './dist/js'),
    publicPath: '/', // 输出解析文件的目录，url 相对于 HTML 页面
    filename: '[name].bundle.js'
  },
  resolve: {
    modules: [path.resolve(__dirname, 'node_modules'), path.join(__dirname, 'src')],
    extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
  },
  module: {
    loaders: [
      {
        test: /\.(jsx|js)$/,
        exclude: /node_modules/,
        loader: "babel-loader",
        query:
          {
            presets: ['es2015', 'react'],
            plugins: [
              ['import', { libraryName: 'antd', style: 'css' }],
            ]
          }
      }, {
        test: /\.scss$/,
        loaders: ['style', 'css', 'sass'],
        include: path.resolve(path.resolve(path.resolve(__dirname), 'build'), 'app')
      }, {
        test: /\.(png|jpg|gif)$/,
        loader: 'url-loader?limit=1024000'
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      },
      {
        test: /\.less$/i, use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', { loader: 'postcss-loader', options: postcssOpts }, 'less-loader']
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin({ filename: '[name].css', allChunks: true }),
  ]
};